/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package BruteForce;

import java.util.Date;
import javax.swing.JOptionPane;

/**
 *
 * @author gustavokatel
 */
public class Senha {
    
    public static void main(String[] args)
    {
        String hra = new Date().toString();
        String senha = JOptionPane.showInputDialog(null, "Digite a senha de teste: ");
        int tam = Integer.parseInt(JOptionPane.showInputDialog(null, "Digite o tamanho: "));
        
        char[] buff = new char[tam];

        for(int i=0;i<buff.length;i++)
            buff[i]= '0';
        System.out.println(buff);
        
        int tot = (int) Math.pow(255, tam);
        int pos = tam-1;
        int count = 0;
        
        while(true)//(count<=tot)
        {
            //System.out.print("#"+count+"/"+tot+": " );
            String b = "";
            for(int i=0;i<buff.length;i++)
            {
                b=b+buff[i];
            }
            //System.out.println(b);
            //if( (count%5550)==0 )
              //  System.out.println(b);
            if(count>0)
            if( (tot/3)%count==0)
                System.out.println(String.valueOf(b).replaceAll("\n", "\\n"));
            if(senha.equals(String.valueOf(buff)))
            {
                //JOptionPane.showMessageDialog(null, "Senha quebrada: "+b+"\nContagem: "+count);
                System.out.println("---------------------------------\nSenha quebrada: "+b+"\nContagem: "+count);
                break;
            }
            //
            buff[pos]=(char)( buff[pos]+1 );
            while(buff[pos]>255 && pos>=0)
            {
                buff[pos]=(char)0;
                pos--;
                buff[pos]=(char)( buff[pos]+1 );
            }
            pos=tam-1;
            //
            count++;
        }
        System.out.println("Count: "+count+"/Tot: "+tot);
        System.out.println("Início: "+hra+" Término:"+new Date());
        
        
    }
    
}
